package com.walker.elk.netty.protobuf.server;


import com.walker.elk.netty.protobuf.DataObject;
import com.walker.elk.netty.protobuf.DataObject.Person;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ProtoBufServerChannelHandler extends SimpleChannelInboundHandler<DataObject.Person> {

	@Override
	public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
		System.out.println("Server Added Handler: " + ctx.channel().id().asLongText());
	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		cause.printStackTrace();
		ctx.close();
	}

	@Override
	public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
		System.out.println("Server Removed Handler: " + ctx.channel().id().asLongText());
	}

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Person msg) throws Exception {
		System.out.println(msg.getName() + " || " + msg.getAge() + " || " + msg.getEmail());
		
	}
	
	

}
